package string;

/**
 * @ClassName MyTest
 * @Author ykx
 * @Date 2024/6/29 19:20
 * @Version 1.0
 */
public class MyTest {
    public static void main(String[] args) {
        MyTest myTest = new MyTest();
        myTest.demo1();
        myTest.getDavg();
        myTest.getDvar();
    }

    private void demo1() {
        System.out.println((50 + 70 + 90) / 3);
        double d = ((50 - 70) * (50 - 70) + (70 - 70) * (70 - 70) + (90 - 70) * (90 - 70)) / 3;
        System.out.println(d);
        System.out.println(Math.sqrt(d));
    }

    private void getDavg() {
        int a1 = 30, a2 = 35, a3 = 40, a4 = 42, a5 = 50;
        double r1 = a1, r2 = getRes(a2, r1), r3 = getRes(a3, r2), r4 = getRes(a4, r3), r5 = getRes(a5, r4);
        System.out.println("r5 = " + r5);

    }

    private double getRes(double current, double last) {
        return current * 0.3 + last * 0.7;
    }

    private void getDvar() {
        int a1 = 30, a2 = 35, a3 = 40, a4 = 42, a5 = 50;
        double davg = a1;
        double dvar = 0;

        davg = calcDavg(a2, davg);
        dvar = calcDvar(a2, davg, dvar);

        davg = calcDavg(a3, davg);
        dvar = calcDvar(a3, davg, dvar);

        davg = calcDavg(a4, davg);
        dvar = calcDvar(a4, davg, dvar);

        davg = calcDavg(a5, davg);
        dvar = calcDvar(a5, davg, dvar);

        System.out.println("dvar = " + dvar);
        System.out.println(Math.sqrt(dvar));
    }

    private double calcDavg(double current, double last) {
        return current * 0.3 + last * 0.7;
    }

    private double calcDvar(double current, double davg, double dvar) {
        return (current - davg) * (current - davg) * 0.3 + dvar * 0.7;
    }

}
